package org.gap.jseed.threading;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.swing.SwingUtilities;

public class SwingInvokeAndWaitProxy implements InvocationHandler {

	@Override
	public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
		method.setAccessible(true);
		SwingUtilities.invokeAndWait(new Runnable() {
			@Override
			public void run() {
				try {
					method.invoke(proxy, args);
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				}
			}
		});
		return null;
	}
}
